package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.user.IVerifyService;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import com.mall.user.dto.UserVerifyRequest;
import com.mall.user.dto.UserVerifyResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;

/**
 * @author Connor
 * @date 2020/12/21
 */
@RestController
@RequestMapping("user")
public class VerifyController {

    @Reference(timeout = 3000,check = false)
    private IVerifyService iVerifyService;

    @Anoymous
    @GetMapping(value = "verify" , params = {"uid", "username"})
    public ResponseData verify(String uid, String username){
        UserVerifyRequest userVerifyRequest = new UserVerifyRequest(username, uid);
        UserVerifyResponse userVerifyResponse = iVerifyService.verifyUser(userVerifyRequest);
        if (userVerifyResponse.getCode().equals(SysRetCodeConstants.REQUEST_CHECK_FAILURE.getCode())) {
            return new ResponseUtil<>().setErrorMsg(SysRetCodeConstants.REQUEST_CHECK_FAILURE.getMessage());
        }
        if (userVerifyResponse.getCode().equals(SysRetCodeConstants.VERIFY_ISEXPIRE_ERROR.getCode())) {
            return new ResponseUtil<String>().setErrorMsg(userVerifyResponse.getMsg());
        }
        if (userVerifyResponse.getCode().equals(SysRetCodeConstants.USER_ISVERFIED_ERROR.getCode())) {
            return new ResponseUtil<>().setErrorMsg(userVerifyResponse.getMsg());
        }
        return new ResponseUtil<String>().setData(userVerifyResponse.getIsverified(), "success");
    }
}
